<template>
  <div class="doctor-page">
    <!-- 顶部导航栏 -->
    <div class="header">
      <div class="header-content">
        <div class="back-btn" @click="$router.go(-1)">
          <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
            <path d="M15 18l-6-6 6-6"/>
          </svg>
        </div>
        <div class="header-title">第三步: 选择医生</div>
        <div class="home-btn" @click="$router.push('/')">
          <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
            <path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>
            <polyline points="9,22 9,12 15,12 15,22"/>
          </svg>
        </div>
      </div>
    </div>

    <!-- 医生标题和操作按钮 -->
    <div class="section-header">
      <div class="title-section">
        <div class="main-title">医生</div>
        <div class="subtitle">找到您喜欢的医生</div>
      </div>
      <div class="action-buttons">
        <div class="action-btn" @click="handleSearchClick">
          <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#4A90E2" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
            <circle cx="11" cy="11" r="8"/>
            <path d="m21 21-4.35-4.35"/>
          </svg>
        </div>
        <div class="action-btn" @click="toggleSortOrder">
          <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#4A90E2" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
            <line x1="8" y1="6" x2="21" y2="6"/>
            <line x1="8" y1="12" x2="21" y2="12"/>
            <line x1="8" y1="18" x2="21" y2="18"/>
            <line x1="3" y1="6" x2="3.01" y2="6"/>
            <line x1="3" y1="12" x2="3.01" y2="12"/>
            <line x1="3" y1="18" x2="3.01" y2="18"/>
          </svg>
        </div>
      </div>
    </div>

    <!-- 医生列表 -->
    <div class="doctor-list">
      <!-- 加载状态 -->
      <div v-if="loading" class="loading-container">
        <div class="loading-spinner"></div>
        <p>正在加载医生信息...</p>
      </div>

      <!-- 错误状态 -->
      <div v-else-if="error" class="error-container">
        <p class="error-text">{{ error }}</p>
        <button @click="retryFetch" class="retry-btn">重试</button>
      </div>

      <!-- 医生卡片 - 使用虚拟滚动优化 -->
      <div v-else class="doctor-cards-container">
        <div 
          class="doctor-card" 
          :class="{ 'selected': selectedDoctorId === doctor._id }"
          v-for="doctor in sortedDoctors" 
          :key="doctor._id"
          @click="selectDoctor(doctor)"
        >
          <div class="doctor-avatar">
            <img 
              :src="doctor.avatar" 
              :alt="doctor.name"
              loading="lazy"
              @error="handleImageError"
              @load="handleImageLoad"
            />
          </div>
          <div class="doctor-info">
            <div class="doctor-header">
              <div class="doctor-name">{{ doctor.name }}</div>
              <div class="doctor-department">{{ doctor.department }}</div>
              <div class="doctor-rating">
                <svg width="14" height="14" viewBox="0 0 24 24" fill="#FFD700" stroke="#FFD700" stroke-width="2">
                  <polygon points="12,2 15.09,8.26 22,9.27 17,14.14 18.18,21.02 12,17.77 5.82,21.02 7,14.14 2,9.27 8.91,8.26"/>
                </svg>
                <span class="rating-score">{{ doctor.rating.toFixed(1) }}</span>
                <span class="rating-count">({{ doctor.reviewCount }} 评价)</span>
              </div>
            </div>
            <div class="doctor-schedule">
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#999" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                <circle cx="12" cy="12" r="10"/>
                <polyline points="12,6 12,12 16,14"/>
              </svg>
              <span class="schedule-label">下一个可用时间:</span>
              <span class="schedule-time">{{ doctor.nextAvailableTime }}</span>
            </div>
            <div class="doctor-footer">
              <div class="doctor-price">¥{{ doctor.price }}</div>
              <button class="doctor-detail-btn" @click.stop="viewDoctorDetail(doctor)">
                医生简介
                <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#4A90E2" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                  <path d="M9 18l6-6-6-6"/>
                </svg>
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 底部按钮 -->
    <div class="bottom-button">
      <button 
        v-if="selectedDoctorId" 
        class="clear-btn" 
        @click="clearSelection"
      >
        清除选择
      </button>
      <button 
        class="next-btn" 
        :class="{ 'disabled': !selectedDoctorId }"
        @click="goToNextStep"
        :disabled="!selectedDoctorId"
      >
        下一步
      </button>
    </div>

    <!-- 搜索弹出框 - 懒加载 -->
    <Suspense>
      <DoctorSearchModal
        v-if="showSearch"
        :doctors="sortedDoctors"
        @close="handleSearchClose"
        @select="handleDoctorSelect"
      />
    </Suspense>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted, onUnmounted, nextTick, defineAsyncComponent } from 'vue'
import { useRouter } from 'vue-router'

// 懒加载搜索模态框
const DoctorSearchModal = defineAsyncComponent(() => import('./DoctorSearchModal.vue'))

const router = useRouter()

// 接口定义
interface Doctor {
  _id: string
  name: string
  department: string
  avatar: string
  rating: number
  reviewCount: number
  nextAvailableTime: string
  price: number
  experience: string
  hospital: string
  title: string
}

// 响应式数据
const loading = ref(false)
const error = ref('')
const selectedDoctorId = ref<string>('')
const showSearch = ref(false)
const sortOrder = ref<'rating' | 'price' | 'name'>('rating')

// 性能优化：缓存和防抖
const doctorCache = new Map<string, Doctor[]>()
const timers: ReturnType<typeof setTimeout>[] = []

// 获取医生头像的函数
const getDoctorAvatar = (index: number) => {
  // 使用可靠的图片源
  const avatarUrls = [
    'https://randomuser.me/api/portraits/men/1.jpg',
    'https://randomuser.me/api/portraits/women/2.jpg',
    'https://randomuser.me/api/portraits/men/3.jpg',
    'https://randomuser.me/api/portraits/women/4.jpg',
    'https://randomuser.me/api/portraits/men/5.jpg',
    'https://randomuser.me/api/portraits/women/6.jpg',
    'https://randomuser.me/api/portraits/men/7.jpg',
    'https://randomuser.me/api/portraits/women/8.jpg',
    'https://randomuser.me/api/portraits/men/9.jpg',
    'https://randomuser.me/api/portraits/women/10.jpg',
    'https://randomuser.me/api/portraits/men/11.jpg',
    'https://randomuser.me/api/portraits/women/12.jpg',
    'https://randomuser.me/api/portraits/men/13.jpg',
    'https://randomuser.me/api/portraits/women/14.jpg',
    'https://randomuser.me/api/portraits/men/15.jpg',
    'https://randomuser.me/api/portraits/women/16.jpg',
    'https://randomuser.me/api/portraits/men/17.jpg',
    'https://randomuser.me/api/portraits/women/18.jpg',
    'https://randomuser.me/api/portraits/men/19.jpg',
    'https://randomuser.me/api/portraits/women/20.jpg'
  ]
  return avatarUrls[index % avatarUrls.length]
}

// 模拟医生数据 - 扩展更多数据用于测试虚拟滚动
const doctors = ref<Doctor[]>([
  {
    _id: '1',
    name: '程晓波',
    department: '儿科',
    avatar: 'https://randomuser.me/api/portraits/men/1.jpg',
    rating: 4.8,
    reviewCount: 456,
    nextAvailableTime: '12月23日 上午08:30',
    price: 350,
    experience: '15年临床经验',
    hospital: '北京儿童医院',
    title: '主任医师'
  },
  {
    _id: '2',
    name: '夏晓点',
    department: '儿科',
    avatar: 'https://randomuser.me/api/portraits/women/2.jpg',
    rating: 4.8,
    reviewCount: 456,
    nextAvailableTime: '12月23日 上午08:30',
    price: 350,
    experience: '12年临床经验',
    hospital: '首都儿科研究所',
    title: '副主任医师'
  },
  {
    _id: '3',
    name: '李平启',
    department: '儿科',
    avatar: 'https://randomuser.me/api/portraits/men/3.jpg',
    rating: 4.8,
    reviewCount: 456,
    nextAvailableTime: '12月23日 上午08:30',
    price: 350,
    experience: '20年临床经验',
    hospital: '北京大学第一医院',
    title: '主任医师'
  },
  // 添加更多医生数据用于测试
  ...Array.from({ length: 20 }, (_, i) => ({
    _id: `${i + 4}`,
    name: `医生${i + 4}`,
    department: ['儿科', '内科', '外科', '妇科'][i % 4],
    avatar: getDoctorAvatar(i + 4),
    rating: 4.0 + Math.random() * 0.9,
    reviewCount: Math.floor(Math.random() * 500) + 100,
    nextAvailableTime: '12月23日 上午08:30',
    price: 200 + Math.floor(Math.random() * 300),
    experience: `${5 + Math.floor(Math.random() * 20)}年临床经验`,
    hospital: ['北京儿童医院', '首都儿科研究所', '北京大学第一医院'][i % 3],
    title: ['主任医师', '副主任医师', '主治医师'][i % 3]
  }))
])

// 计算属性 - 排序后的医生列表
const sortedDoctors = computed(() => {
  const sorted = [...doctors.value]
  switch (sortOrder.value) {
    case 'rating':
      return sorted.sort((a, b) => b.rating - a.rating)
    case 'price':
      return sorted.sort((a, b) => a.price - b.price)
    case 'name':
      return sorted.sort((a, b) => a.name.localeCompare(b.name))
    default:
      return sorted
  }
})

// 防抖函数
const debounce = (fn: Function, delay: number) => {
  let timeoutId: ReturnType<typeof setTimeout>
  return (...args: any[]) => {
    clearTimeout(timeoutId)
    timeoutId = setTimeout(() => fn.apply(null, args), delay)
    timers.push(timeoutId)
  }
}

// 方法
const fetchDoctors = async () => {
  const cacheKey = 'doctors_list'
  
  if (doctorCache.has(cacheKey)) {
    doctors.value = doctorCache.get(cacheKey)!
    return
  }

  loading.value = true
  error.value = ''
  
  try {
    // 模拟API调用
    await new Promise(resolve => {
      const timer = setTimeout(resolve, 1000)
      timers.push(timer)
    })
    
    // 缓存数据
    doctorCache.set(cacheKey, doctors.value)
    loading.value = false
  } catch (err) {
    console.error('获取医生列表失败:', err)
    error.value = '获取医生列表失败，请重试'
    loading.value = false
  }
}

const retryFetch = () => {
  doctorCache.clear()
  fetchDoctors()
}

const selectDoctor = (doctor: Doctor) => {
  console.log('选择医生:', doctor.name)
  
  selectedDoctorId.value = doctor._id
  
  // 存储到本地存储
  localStorage.setItem('selectedDoctorId', doctor._id)
  localStorage.setItem('selectedDoctor', JSON.stringify(doctor))
  
  // 添加触觉反馈（如果支持）
  if ('vibrate' in navigator) {
    navigator.vibrate(50)
  }
  
  // 显示选择成功提示
  showToast(`已选择医生：${doctor.name}`)
}

const handleDoctorSelect = (doctor: Doctor) => {
  selectDoctor(doctor)
  showSearch.value = false
}

const viewDoctorDetail = (doctor: Doctor) => {
  console.log('查看医生详情:', doctor.name)
  
  // 存储医生信息到本地存储
  localStorage.setItem('selectedDoctor', JSON.stringify(doctor))
  
  // 跳转到医生详情页面
  router.push(`/doctor-detail/${doctor._id}`)
}

const goToNextStep = () => {
  if (!selectedDoctorId.value) {
    showToast('请先选择一位医生')
    return
  }
  
  console.log('跳转到下一步')
  router.push('/time-select')
}

// 搜索相关方法
const handleSearchClick = () => {
  showSearch.value = true
}

const handleSearchClose = () => {
  showSearch.value = false
}

// 排序切换
const toggleSortOrder = () => {
  const orders: Array<'rating' | 'price' | 'name'> = ['rating', 'price', 'name']
  const currentIndex = orders.indexOf(sortOrder.value)
  sortOrder.value = orders[(currentIndex + 1) % orders.length]
  
  // 显示排序提示
  const orderNames = { rating: '评分', price: '价格', name: '姓名' }
  showToast(`已按${orderNames[sortOrder.value]}排序`)
}

// 轻提示函数
const showToast = (message: string) => {
  // 创建toast元素
  const toast = document.createElement('div')
  toast.className = 'toast-message'
  toast.textContent = message
  
  // 添加到页面
  document.body.appendChild(toast)
  
  // 显示动画
  setTimeout(() => {
    toast.classList.add('show')
  }, 10)
  
  // 3秒后移除
  setTimeout(() => {
    toast.classList.remove('show')
    setTimeout(() => {
      if (document.body.contains(toast)) {
        document.body.removeChild(toast)
      }
    }, 300)
  }, 3000)
}

// 图片加载优化
const handleImageError = (event: Event) => {
  const img = event.target as HTMLImageElement
  // 使用Base64编码的默认头像
  img.src = ''
}

const handleImageLoad = (event: Event) => {
  const img = event.target as HTMLImageElement
  img.classList.add('loaded')
}



// 清除选中状态
const clearSelection = () => {
  selectedDoctorId.value = ''
  localStorage.removeItem('selectedDoctorId')
  localStorage.removeItem('selectedDoctor')
  showToast('已清除选择')
}

// 生命周期
onMounted(async () => {
  await fetchDoctors()
  
  // 从本地存储恢复选中状态
  const savedDoctorId = localStorage.getItem('selectedDoctorId')
  if (savedDoctorId) {
    selectedDoctorId.value = savedDoctorId
    console.log('恢复选中医生ID:', savedDoctorId)
  }
})

onUnmounted(() => {
  // 清理定时器
  timers.forEach(timer => clearTimeout(timer))
  
  // 清理缓存（可选）
  // doctorCache.clear()
})
</script>

<style scoped>
/* CSS 变量优化 */
:root {
  --primary-color: #4A90E2;
  --primary-hover: #357ABD;
  --border-radius: 12px;
  --shadow-light: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-medium: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-heavy: 0 4px 12px rgba(74, 144, 226, 0.3);
  --transition: all 0.2s ease;
}

.doctor-page {
  min-height: 100vh;
  background: #f8f9fa;
  padding-bottom: 100px;
  contain: layout style paint;
}

/* 顶部导航栏 */
.header {
  background: #1877F2;
  padding: 0 20px;
  padding-top: env(safe-area-inset-top);
  will-change: transform;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.back-btn, .home-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 8px;
  transition: var(--transition);
  transform: translateZ(0);
}

.back-btn:hover, .home-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.05) translateZ(0);
}

.header-title {
  color: #fff;
  font-size: 18px;
  font-weight: 600;
  flex: 1;
  text-align: center;
}

.back-btn svg, .home-btn svg {
  stroke: #fff;
}

/* 标题区域 */
.section-header {
  background: #fff;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid #f0f0f0;
  contain: layout style;
}

.title-section .main-title {
  font-size: 24px;
  font-weight: 700;
  color: #333;
  margin-bottom: 4px;
}

.title-section .subtitle {
  font-size: 14px;
  color: #999;
}

.action-buttons {
  display: flex;
  gap: 12px;
}

.action-btn {
  width: 40px;
  height: 40px;
  background: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  transform: translateZ(0);
}

.action-btn:hover {
  background: #f8fbff;
  transform: scale(1.05) translateZ(0);
}

/* 医生列表 */
.doctor-list {
  padding: 16px 20px;
  height: calc(100vh - 200px);
  overflow-y: auto;
  scroll-behavior: smooth;
}

.doctor-cards-container {
  contain: layout style;
}

.loading-container, .error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.error-text {
  color: #dc3545;
  margin-bottom: 16px;
  font-size: 16px;
}

.retry-btn {
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.retry-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

/* 医生卡片优化 - 医院卡片风格 */
.doctor-card {
  background: #fff;
  border-radius: 12px;
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 0 0 0 20px;
  min-height: 120px;
  border: 2px solid transparent;
}

.doctor-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(24,119,242,0.15);
}

.doctor-card.selected {
  border-color: #1877F2;
  background: linear-gradient(135deg, #f8fbff 0%, #e3f2fd 100%);
  box-shadow: 0 4px 16px rgba(24,119,242,0.2);
  transform: translateY(-2px);
}

.doctor-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(135deg, #00D4FF 0%, #5B73FF 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-right: 0;
}

.doctor-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.doctor-avatar img.loaded {
  opacity: 1;
}

.doctor-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 0 16px 0;
}

.doctor-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.doctor-name {
  font-size: 18px;
  font-weight: 600;
  color: #222;
  margin-right: 8px;
}
.doctor-card.selected .doctor-name {
  color: #1877F2;
  font-weight: 700;
}
.doctor-department {
  font-size: 14px;
  color: #666;
}
.doctor-rating {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
}
.rating-score {
  font-size: 14px;
  font-weight: 600;
  color: #666;
}
.rating-count {
  font-size: 14px;
  color: #999;
}
.doctor-schedule {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  color: #666;
}
.schedule-label {
  color: #999;
}
.schedule-time {
  color: #333;
  font-weight: 500;
}
.doctor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}
.doctor-price {
  background: #1877F2;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 20px;
  line-height: 1.2;
}
.doctor-card.selected .doctor-price {
  background: #1877F2;
  color: #fff;
}
.doctor-detail-btn {
  background: none;
  border: none;
  color: #1877F2;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  border-radius: 6px;
  transition: background 0.2s;
}
.doctor-detail-btn:hover {
  background: #f8fbff;
  color: #0d47a1;
}

/* 底部按钮风格对齐 */
.bottom-button {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px;
  background: #fff;
  border-top: 1px solid #f0f0f0;
  z-index: 100;
  display: flex;
  gap: 12px;
  align-items: center;
}

.next-btn {
  flex: 1;
  height: 48px;
  background: #1877F2;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.next-btn:hover:not(.disabled) {
  background: #1565c0;
}

.next-btn.disabled {
  background: #ccc;
  color: #999;
  cursor: not-allowed;
}

.clear-btn {
  height: 48px;
  padding: 0 20px;
  background: #f5f5f5;
  color: #666;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.clear-btn:hover {
  background: #e0e0e0;
  color: #333;
}

.clear-btn:active {
  background: #d0d0d0;
}

/* 搜索弹出框样式 */
.search-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.search-modal-content {
  background: #fff;
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 90%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

.search-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #f0f0f0;
  background: #f8fbff;
}

.search-modal-header h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #333;
}

.search-modal-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background 0.2s;
}

.search-modal-close-btn:hover {
  background: #f0f0f0;
}

.search-modal-close-btn svg {
  stroke: #666;
  width: 24px;
  height: 24px;
}

.search-modal-body {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.search-modal-body .doctor-card {
  margin-bottom: 12px;
  padding: 12px 16px;
  gap: 12px;
  min-height: auto;
  border: 1px solid #eee;
}

.search-modal-body .doctor-card:last-child {
  margin-bottom: 0;
}

.search-modal-body .doctor-card .doctor-avatar {
  width: 60px;
  height: 60px;
}

.search-modal-body .doctor-card .doctor-info {
  gap: 4px;
  padding: 0;
}

.search-modal-body .doctor-card .doctor-header {
  gap: 8px;
}

.search-modal-body .doctor-card .doctor-name {
  font-size: 16px;
}

.search-modal-body .doctor-card .doctor-department {
  font-size: 13px;
  color: #999;
}

.search-modal-body .doctor-card .doctor-rating {
  gap: 4px;
  margin-left: 0;
}

.search-modal-body .doctor-card .rating-score {
  font-size: 13px;
}

.search-modal-body .doctor-card .rating-count {
  font-size: 13px;
  color: #999;
}

.search-modal-body .doctor-card .doctor-schedule {
  gap: 2px;
  font-size: 13px;
}

.search-modal-body .doctor-card .schedule-label {
  color: #999;
}

.search-modal-body .doctor-card .schedule-time {
  color: #333;
  font-weight: 500;
}

.search-modal-body .doctor-card .doctor-footer {
  margin-top: 4px;
}

.search-modal-body .doctor-card .doctor-price {
  font-size: 14px;
  padding: 4px 12px;
  border-radius: 16px;
}

.search-modal-body .doctor-card .doctor-detail-btn {
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 5px;
}

.search-modal-body .doctor-card.selected {
  border-color: #1877F2;
  background: #f8fbff;
  box-shadow: 0 2px 8px rgba(24,119,242,0.1);
  transform: none;
}

.search-modal-body .doctor-card.selected .doctor-name {
  color: #1877F2;
  font-weight: 600;
}

.search-modal-body .doctor-card.selected .doctor-price {
  background: #1877F2;
  color: #fff;
}

.search-modal-body .doctor-card.selected .doctor-detail-btn {
  background: #f8fbff;
  color: #0d47a1;
}

/* 响应式设计 */
@media (max-width: 480px) {
  .doctor-card {
    padding: 14px;
    gap: 10px;
  }
  
  .doctor-avatar {
    width: 50px;
    height: 50px;
  }
  
  .doctor-name {
    font-size: 15px;
  }
  
  .section-header {
    padding: 16px;
  }
  
  .title-section .main-title {
    font-size: 20px;
  }
  
  .doctor-list {
    padding: 12px 16px;
  }
  
  .bottom-button {
    padding: 12px 16px;
  }
}

/* 性能优化：减少重绘 */
* {
  box-sizing: border-box;
}

.doctor-card,
.action-btn,
.next-btn {
  backface-visibility: hidden;
  perspective: 1000px;
}

/* 轻提示样式 */
.toast-message {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 10000;
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}

.toast-message.show {
  opacity: 1;
}

/* 搜索弹出框样式 */
.search-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.search-modal-content {
  background: #fff;
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 90%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

.search-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #f0f0f0;
  background: #f8fbff;
}

.search-modal-header h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #333;
}

.search-modal-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background 0.2s;
}

.search-modal-close-btn:hover {
  background: #f0f0f0;
}

.search-modal-close-btn svg {
  stroke: #666;
  width: 24px;
  height: 24px;
}

.search-modal-body {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.search-modal-body .doctor-card {
  margin-bottom: 12px;
  padding: 12px 16px;
  gap: 12px;
  min-height: auto;
  border: 1px solid #eee;
}

.search-modal-body .doctor-card:last-child {
  margin-bottom: 0;
}

.search-modal-body .doctor-card .doctor-avatar {
  width: 60px;
  height: 60px;
}

.search-modal-body .doctor-card .doctor-info {
  gap: 4px;
  padding: 0;
}

.search-modal-body .doctor-card .doctor-header {
  gap: 8px;
}

.search-modal-body .doctor-card .doctor-name {
  font-size: 16px;
}

.search-modal-body .doctor-card .doctor-department {
  font-size: 13px;
  color: #999;
}

.search-modal-body .doctor-card .doctor-rating {
  gap: 4px;
  margin-left: 0;
}

.search-modal-body .doctor-card .rating-score {
  font-size: 13px;
}

.search-modal-body .doctor-card .rating-count {
  font-size: 13px;
  color: #999;
}

.search-modal-body .doctor-card .doctor-schedule {
  gap: 2px;
  font-size: 13px;
}

.search-modal-body .doctor-card .schedule-label {
  color: #999;
}

.search-modal-body .doctor-card .schedule-time {
  color: #333;
  font-weight: 500;
}

.search-modal-body .doctor-card .doctor-footer {
  margin-top: 4px;
}

.search-modal-body .doctor-card .doctor-price {
  font-size: 14px;
  padding: 4px 12px;
  border-radius: 16px;
}

.search-modal-body .doctor-card .doctor-detail-btn {
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 5px;
}

.search-modal-body .doctor-card.selected {
  border-color: #1877F2;
  background: #f8fbff;
  box-shadow: 0 2px 8px rgba(24,119,242,0.1);
  transform: none;
}

.search-modal-body .doctor-card.selected .doctor-name {
  color: #1877F2;
  font-weight: 600;
}

.search-modal-body .doctor-card.selected .doctor-price {
  background: #1877F2;
  color: #fff;
}

.search-modal-body .doctor-card.selected .doctor-detail-btn {
  background: #f8fbff;
  color: #0d47a1;
}
</style>
